# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=nldev
pkgver=0.3_git20160406
pkgrel=0
verbase=0.3
pkgdesc="A simple netlink device manager"
url="http://git.r-36.net/nldev/"
arch="all"
license="MIT"
depends=""
depends_dev=""
makedepends="linux-headers"
install=""
subpackages="$pkgname-doc"
source="https://dev.alpinelinux.org/archive/$pkgname/$pkgname-$pkgver.tar.gz
	${pkgname}.initd
	${pkgname}-trigger.initd

	0001-Revert-nldev-set-kernel-buffer-to-16kb.patch
	0002-Preserve-the-PATH-environment-variable.patch
	0003-Change-the-default-mdev-path-to-sbin-mdev.patch"

disturl="dev.alpinelinux.org:/archive/$pkgname"
reporev="d2974b64d4e8bab0e08c6395c2925c94e13a3ca5"
giturl="git://git.r-36.net/$pkgname"

_builddir="$srcdir"/$pkgname-$pkgver
build() {
	make CFLAGS="$CFLAGS \${INCS} \${CPPFLAGS}" \
		LDFLAGS="$LDFLAGS \${LIBS}" CC="${CC:-gcc}" \
		-C "$_builddir" || return 1
}

package() {
	cd "$_builddir"
	make DESTDIR="$pkgdir" PREFIX=/ \
		MANPREFIX=/usr/share/man install || return 1

	# Move nldev to /sbin
	mkdir -p "$pkgdir"/sbin/
	mv "$pkgdir"/bin/$pkgname "$pkgdir"/sbin/ || return 1

	# We don't need run_nldev, use the init script instead
	rm -f "$pkgdir"/bin/run_$pkgname

	# Install OpenRC service files
	for service in ${pkgname} ${pkgname}-trigger; do
		install -Dm755 "$srcdir"/$service.initd \
			"$pkgdir"/etc/init.d/$service || return 1
	done

	# Install utility scripts
	mkdir -p "$pkgdir"/lib/$pkgname || return 1
	install -m755 mdev/lib/* "$pkgdir"/lib/$pkgname/ || return 1

	# Install additional documentation
	mkdir -p "$pkgdir"/usr/share/doc/$pkgname/examples/
	install -m644 FIXES.md README.md \
		"$pkgdir"/usr/share/doc/$pkgname/ || return 1
	install -m644 mdev/etc/* \
		"$pkgdir"/usr/share/doc/$pkgname/examples || return 1
	install -m755 mdev/lib/* \
		"$pkgdir"/usr/share/doc/$pkgname/examples || return 1
}

md5sums="498f8815a0864382a94feb0b67c9897e  nldev-0.3_git20160406.tar.gz
3bc9f761fe7b57c538089bb3875cb1cd  nldev.initd
f57e754d52f06529e82979db8bd3106e  nldev-trigger.initd
e565d056ea4dd5c74b308c397e7e27e5  0001-Revert-nldev-set-kernel-buffer-to-16kb.patch
a921cc18e879114a1c8009d2f9cfb552  0002-Preserve-the-PATH-environment-variable.patch
bfc26b861b96d253b89defb14697523a  0003-Change-the-default-mdev-path-to-sbin-mdev.patch"
sha256sums="1580e7d65a5079ac83ae6c58e9445533f151109405d6c191d5074bda302014f1  nldev-0.3_git20160406.tar.gz
3e88e5a53b0db3724f03fb4b9ec90b42b2c9734516db6d9f11d125ed2b365776  nldev.initd
1ab6163a350a7c7e377f0e6ea9070c736c434c9a55c3ef28438af552effa1714  nldev-trigger.initd
22e295e2f3391c139b735098f11c8dfabf835373ad80a1d12f0df3d4ee4ffc7d  0001-Revert-nldev-set-kernel-buffer-to-16kb.patch
7d47ff02a42273446fed0774658d0f9f199e4d9b1ede3e02143985db6fab3d0f  0002-Preserve-the-PATH-environment-variable.patch
a861166721ecae633bffa91a6ac055c23f3ad5a1070cb7c9a303816326328619  0003-Change-the-default-mdev-path-to-sbin-mdev.patch"
sha512sums="d0aadfbd29b22a7efe52c9e0976b7e24313a9827ac52ed726324f7a444ae89cca8a1ea55448694849ca6e636d6d8ec19614a9e58f1298c8f2d4c3c58f930b687  nldev-0.3_git20160406.tar.gz
1e2b4ca1f7b6c9a6d36ac659acf5ef8fb0aef49c7db69dc3f94ef54bfd024a34ce849092c23f67934ea36e19df3b76b01eb347daa423a8eaf63b556077d2af64  nldev.initd
0e34e2db640bcfe7ba8b8e2a07a681906e7e6a2fe267f255a216c36e93db5096b7ed4865935ef448aabc8c4c130a786e555113d8ba90bed58f4ae3450890a1ea  nldev-trigger.initd
7821f54b0eeab13355d0a534bafc7c07250b91dcd43e334ffe9bcd9ee601680489ade4aa97b45543d38be93279c3cb11357d58497a3fb7e66052bf743917088f  0001-Revert-nldev-set-kernel-buffer-to-16kb.patch
3d592c4f5a8ae1081aa3780d099b98e3c9869cecc1a3d06dff096e8ee1ea00059c8d5c702fdbb6c5829a429a813f37deab7de7164d38887834d62c0da6165173  0002-Preserve-the-PATH-environment-variable.patch
b9128249077981718d34477b5b81655f256f0a28a549099ed20a611d5aeb54e0d837debe623d6f65071a036fd31322454bb99906058e6309b18c0178c5ce3e5e  0003-Change-the-default-mdev-path-to-sbin-mdev.patch"
